﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Lead2012.Business
{
    public class LeadStatusRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();
        public List<LeadStatus> GetAll()
        {
            return (from c in entities.LeadStatuses select c).ToList();
        }
        
        public LeadStatus GetSingle(int id)
        {
            return (from _object in entities.LeadStatuses where _object.StatusId == id select _object).FirstOrDefault();
        }

        
        public void Create(LeadStatus _object)
        {
            entities.AddToLeadStatuses(_object);
            entities.SaveChanges();
        }

        public void Update(LeadStatus _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int id)
        {
            var _object = (from _list in entities.LeadStatuses where _list.StatusId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
        public void Save(LeadStatus _object)
        {
            _object.EntityKey = (from LeadStatus ac in entities.LeadStatuses where ac.StatusId == _object.StatusId select ac).FirstOrDefault().EntityKey;
            entities.SaveChanges();
        }
    }
}